<script src="Libraries/js/js.js"></script>
<?php
	include_once('Models/HocPhan.php');
	include_once('Configs/paging.php');
    include_once('Configs/database.php');
	include_once('Models/HocKiNamHoc.php');
?>
<script language="javascript">
	function checkValue(){
		if (document.xemthoikhoabieu.cbonamhoc.selectedIndex == 0){
			alert("Xin vui lòng chọn năm học!");
			return false;
		}
		if (document.xemthoikhoabieu.cbohocki.selectedIndex == 0){
			alert("Xin vui lòng chọn học kì!");
			return false;
		}
		return true;
	}
	
 function wopen(url, name, w, h){
	  w += 32;
	  h += 96;
	  wleft = (screen.width - w) / 2;
	  wtop = (screen.height - h) / 2;
	  
	  if (wleft < 0) {
		w = screen.width;
		wleft = 0;
	  }
	  if (wtop < 0) {
		h = screen.height;
		wtop = 0;
	  }
	  var win = window.open(url,
		name,
		'width=' + w + ', height=' + h + ', ' +
		'left=' + wleft + ', top=' + wtop + ', ' +
		'location=no, menubar=no, ' +
		'status=no, toolbar=no, scrollbars=yes, resizable=no');
	  // Just in case width and height are ignored
	  win.resizeTo(w, h);
	  // Just in case left and top are ignored
	  win.moveTo(wleft, wtop);
	  win.focus();
}
function printTL(namhoc,hocki,maso){
	
	wopen('inThoiKhoaBieu.php?namhoc='+namhoc+'&hocki='+hocki+'&maso='+maso+'','780','580');
}  
</script>
<form name="xemthoikhoabieu" method="POST">
<table align="center" class="font" width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class=main_1><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td align=center class=main_1>Xem thời khóa biểu </td>
    <td class=main_1><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
  <tr bgcolor="#dae9f3">
    <td class="border_1" colspan="3" valign="top">
        	<table border="0" align="center"  >
                <tr>
                    <td >&nbsp;</td>
                </tr>
			</table>
            <table border="0" align="center"  >
               
                <tr>
                    <td align=right><label>Năm học </label>&nbsp;
                      <select name="cbonamhoc" onchange="document.xemthoikhoabieu.cbohocki.selectedIndex=0;">
                        <option value=" "></option>
                        <?php
										$hknh = new HocKiNamHoc();
                                		$result = $hknh->dsNamHoc();
                                		while ($rows=mysql_fetch_array($result)){
                                    		echo "<option value='".$rows['namhoc']."'";				
				                    		echo ">".$rows['namhoc']."</option>";
                                		}
                                		if (isset($_POST['cbonamhoc'])){
                                    		echo "<script language=\"javascript\">for(var i=0;i<document.xemthoikhoabieu.cbonamhoc.length;i++){if(document.xemthoikhoabieu.cbonamhoc[i].value=='$namhoc'){document.xemthoikhoabieu.cbonamhoc.selectedIndex=i;break;}}</script>";
                                		}
                                	?>
                      </select>                      &nbsp;Học kì&nbsp;
                        <select name="cbohocki" onchange="showHocPhan(document.capnhatlophp.cbonamhoc.value,this.value);">
						<option value=""></option>
                      <option value="1"  <?php if ($_POST['cbohocki']==1) echo "selected='selected'"; ?>>1</option>
                      ;
                            
                      <option value="2" <?php if ($_POST['cbohocki']==2) echo "selected='selected'"; ?>>2</option>
                      ;
							
                      <option value="3" <?php if ($_POST['cbohocki']==3) echo "selected='selected'"; ?>>Hè</option>
                      ;      
                        
                    
                    </select>&nbsp;
					<?php 
						if ($_SESSION['nmaquyen']=='AD')
                        {
                            
                            echo "MSCB&nbsp;<input type='text' name='txtmaso' size='10'/>";
                        }
                        if ($_SESSION['nmaquyen']=='BM'){
                            $db = new database();
                            $db->setQuery("select a.mabm from CanBoGiangDay a,BoMon b where maso='".$_SESSION['nmaso']."' and a.mabm=b.mabm");
                            $result = $db->fetchAll();
                            $rows = mysql_fetch_array($result);
                            $mabm = $rows['mabm'];
                            $db->setQuery("select a.maso, concat(holot,' ',ten) as hoten
											from CanBoGiangDay a, CanBo b where a.mabm='".$mabm."' and a.maso=b.maso");
                            $resultcb = $db->fetchAll();
                            echo "Cán Bộ&nbsp;<select name='cbomaso'>";
                            echo "<option value=' '></option>";
                            while($rowscb = mysql_fetch_array($resultcb)){
                                 echo "<option value='".$rowscb['maso']."'>".$rowscb['hoten']."</option>";
                            }
                            echo "</select>";
                        }
                        if ($_SESSION['nmaquyen']=='DV'){
                            $db = new database();
                            $db->setQuery("select b.makhoa from CanBoGiangDay a,BoMon b,Khoa c where maso='".$_SESSION['nmaso']."' and a.mabm=b.mabm and b.makhoa=c.makhoa");
                            $result = $db->fetchAll();
                            $rows = mysql_fetch_array($result);
                            $makhoa = $rows['makhoa'];
                            $db->setQuery("select a.maso,concat(holot,' ',ten) as hoten  from CanBoGiangDay a,BoMon b,Khoa c,Canbo d where b.makhoa='".$makhoa."' and a.mabm=b.mabm and b.makhoa=c.makhoa and a.maso=d.maso");
                            $resultcb = $db->fetchAll();
                            echo "Cán Bộ&nbsp;<select name='cbomaso'>";
                            echo "<option value=' '></option>";
                            while($rowscb = mysql_fetch_array($resultcb)){
                                 echo "<option value='".$rowscb['maso']."'>".$rowscb['hoten']."</option>";
                            }
                            echo "</select>";
                        }
					?>
					</td>
                </tr>
				
            </table>
       		<table border="0" align="center"  >
                <tr>
       	          <td align=center><label></label>
			      <input type="submit" name="btnxem" value="Xem" class="button_1" onclick="return checkValue();"/></td>
                </tr>
			</table>
           

    </td>
  </tr>
</table>
<br />
<p>&nbsp;</p>
<?php
if (isset($_POST['btnxem']))
{
?>
<table align="center" class="font" width="650" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="main_1"><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td align="center" class="main_1">Thời Khóa Biểu - Học kì:<?php echo $hocki?>-Năm học:<?php echo $namhoc?></td>
    <td class="main_1"><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
  
  
  
  
    <tr >
    	<td class="border_1" colspan="3" valign="top">
            <table width="800" class="border_1" style="border:none" id="tbmain" cellpadding="0" cellspacing="0">
                <tr>
                    <td colspan="10" align="center" class="main_3" >Cán Bộ: <?php echo $hoten?> - MSCB: <?php echo $maso?></td>
                </tr>
                <tr>
                  <td width="30" align="center" class="main_3" >Thứ</td>
                  <td width="60" align="center" class="main_3">Mã HP</td>
                  <td width="50" align="center" class="main_3">Nhóm</td>
                  <td width="250" align="center" class="main_3">Tên Học Phần </td>
                  <td width="80" align="center" class="main_3">Lớp HP</td>
                  <td width="50" align="center" class="main_3">Sĩ Số</td>
                  <td width="50" align="center" class="main_3">Tiết Học </td>
                  
                  <td width="50" align="center" class="main_3">Phòng</td>
                  <td width="80" align="center" class="main_3">Tuần Học </td>
                </tr>
				<?php
				$num = mysql_num_rows($result1);
				if ($num > 0)
				{
				
					$i = 0;
					while ($rows1 = mysql_fetch_array($result1))
					{
						$i++;
						$c = 2-$i%2;
					?>
					<tr>
						<td align="center" class="main_3"><?php echo $rows1['thu']?></td>
						<td class='level_1_<?php echo $c?>' align="center"><?php echo $rows1['mahp']?></td>
						<td class='level_1_<?php echo $c?>' align="center"><?php echo $rows1['kihieu']?></td>
						<td class='level_1_<?php echo $c?>' align="left"><?php echo $rows1['tenhp']?></td>
						<td class='level_1_<?php echo $c?>' align="center"><?php echo $rows1['malophp']?></td>
						<td class='level_1_<?php echo $c?>' align="center"><?php echo $rows1['siso']?></td>
						<td class='level_1_<?php echo $c?>' align="center"><?php echo tietHocTrongTKB($rows1['tietbd'],$rows1['sotiet'])?></td>   
						
						<td class='level_1_<?php echo $c?>' align="center"><?php echo $rows1['maphong']?></td>
						<td class='level_1_<?php echo $c?>' align="center"><?php echo $rows1['tuanhoc']?></td>
					</tr>
					<?php
					}
				}
				else
				{
				?>
					<tr>
						<td class='level_1_1' align="center" colspan="10"><b>Không có dữ liệu</b></td>
						
					</tr>
					<?php
					}
					?>
        </table>        </td>
  </tr>
    
</table>
<br />
<table align="center" class="font" width="650" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="main_1"><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td align="center" class="main_1">Học Phần Không Xếp Thời Khóa Biểu </td>
    <td class="main_1"><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
  
  
  
  
    <tr >
    	<td class="border_1" colspan="3" valign="top">
            <table width="800" class="border_1" style="border:none" id="tbmain" cellpadding="0" cellspacing="0">
				<tr>
                    <td align="center" width="30" class="main_3" >STT</td>
                    <td align="center" class="main_3" width="60">Mã HP </td>
                    <td align="center" class="main_3" width="50">KH</td>
                    <td align="center" class="main_3" width="400">Tên Học Phần </td>
					<td align="center" class="main_3" width="100">Lớp HP</td>
					<td align="center" class="main_3" width="50">Sĩ số</td>

	                <td align="center" class="main_3" width="80">Tuần học </td>
                </tr>
			<?php
				$num = mysql_num_rows($result2);
				
				if ($num > 0)
				{
				
					$i = 0;
					while ($rows2 = mysql_fetch_array($result2))
					{
						$i++;
						$c = 2-$i%2;
					?>
                
                <tr>
            		<td align="center" class="main_3"><?php echo $i?></td>
            		<td class='level_1_<?php echo $c?>' align="center"><?php echo $rows2['mahp']?></td>
            		<td class='level_1_<?php echo $c?>' align="center"><?php echo $rows2['kihieu']?></td>
                    <td class='level_1_<?php echo $c?>' align="left"><?php echo $rows2['tenhp']?></td>
					<td class='level_1_<?php echo $c?>' align="center"><?php echo $rows2['malophp']?></td>
                    <td class='level_1_<?php echo $c?>' align="center"><?php echo $rows2['siso']?></td>
            		<td class='level_1_<?php echo $c?>' align="center"><?php echo $rows2['tuanhoc']?></td>
                </tr>
				<?php
					}
				}
				else
				{
				?>
					<tr>
						<td class='level_1_1' align="center" colspan="7"><b>Không có dữ liệu</b></td>
					</tr>
					<?php
					}
					?>
        </table>        </td>
  </tr>
    
</table>
<div align="center"><br />
  
    </table>
    <span >
    
    </span><input type="button" value="Download TKB" onclick="printTL('<?php echo $namhoc?>','<?php echo $hocki?>','<?php echo $maso?>');" class="button_1">
    </div>
<?php
}
?>
</form>
<p><br />
  
 
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
